There is the data: atp_tennis containing the following columns: ['Tournament', 'Date', 'Series', 'Court', 'Surface', 'Round', 'Best of', 'Player_1', 'Player_2', 'Winner', 'Rank_1', 'Rank_2', 'Pts_1', 'Pts_2', 'Odd_1', 'Odd_2', 'score'].  
--- The description for each column this data is:
Tournament: Name of the tennis tournament (Brisbane International, Chennai Open, Qatar Exxon Mobil Open ...etc)
Date: Date the match was played (year-month-day)
Series: Category or level of the tennis tournament (ATP250, ATP500, Masters1000 and Grand Slams offer 250, 500, 1000, and 2000 ranking points to the winner seperately.)
Court: Place the match was held (Indoors or Outdoors)
Surface: Type of court surface (Hard, Grass and Clay)
Round: Stage of the tournament (1st Round, 2nd Round, Quarterfinals, Semifinal and The Final)
Best of: Tourament systems ("best of 3" or "best of 5")
Player_1: Name of the first competitor in each match
Player_2: Name of the second competitor in each match
Winner: Name of the Player_1 or Player_2 who won the match 
Rank_1: World rankings of the Player_1 at the time of the match
Rank_2: World rankings of the Player_2 at the time of the match
Pts_1: Ranking points held by Player_1 before the match (accumulated over the season and higher points typically indicate a more successful player)
Pts_2: Ranking points held by Player_2 before the match
Odd_1: Betting odds for Player_1 (reflecting their perceived chances of winning)
Odd_2: Betting odds for Player_2 
Score: Final score of the match ("score of Player_1" - "score of Player_2")
---
Considering contents from the dataset and requirements from user. Please note DO NOT CHANGE FILE AND VARIABLE NAMES THAT I HAVE SET!
Interactions begin:
[USER (data scientist)]: Can you help me change the 'Date' column to a datetime format? Please generate a Series by converting the 'Date' column to datetime format in the ATP tennis dataset.

[YOU (AI assistant)]: Sure! You can use this code to change the 'Date' column to datetime format :
'''
import pandas as pd
import pickle
from decision_company import read_csv_file, convert_to_datetime

# Load the dataset
atp_tennis = read_csv_file("atp_tennis.csv")

# Convert the 'Date' column to datetime format
atp_tennis['Date'] = convert_to_datetime(atp_tennis['Date'])

print(atp_tennis['Date'])

'''

[USER (data scientist)]: What's the most recent date in the dataset? Please generate a value of the most recent date in the ATP tennis dataset.

[YOU (AI assistant)]: To find the most recent date, you can use this code :
'''
import pandas as pd
import pickle
from decision_company import read_csv_file, get_max

# Load the dataset
atp_tennis = read_csv_file("atp_tennis.csv")

# Find the last date in the dataset
last_date = get_max(atp_tennis['Date'])

print(last_date)

'''

[USER (data scientist)]: I'd like to see only the matches from the last five years. Can you help me with that? Please generate and display a DataFrame containing matches from the last five years in the ATP tennis dataset.

[YOU (AI assistant)]: Absolutely! You can use this code to filter the dataset for matches from the last five years :
'''
import pandas as pd
import pickle
from decision_company import read_csv_file, create_date_offset, filter_by_date

# Load the dataset
atp_tennis = read_csv_file("atp_tennis.csv")

# Filter the dataset to only include matches from the last five years
five_years_ago = last_date - create_date_offset(years=5)
recent_matches = filter_by_date(atp_tennis, 'Date', five_years_ago)

print(recent_matches)

'''

[USER (data scientist)]: Can you show me the top 10 ranked players from the filtered data? Please generate a DataFrame listing the top 10 ranked players based on their minimum ranking in recent matches from the ATP tennis dataset.

[YOU (AI assistant)]: Sure thing! Here's the code to find the top 10 ranked players from the filtered data :
'''
import pandas as pd
import pickle
from decision_company import read_csv_file, get_min_value, sort_by_values, get_first_n_rows, concatenate_objects, rename_columns, bind_dataframe

# Load the dataset
atp_tennis = read_csv_file("atp_tennis.csv")

concatenated_data = concatenate_objects(
    recent_matches[['Player_1', 'Rank_1']],
    rename_columns(recent_matches[['Player_2', 'Rank_2']], {'Player_2': 'Player_1', 'Rank_2': 'Rank_1'})
)
grouped_data = bind_dataframe(concatenated_data, 'Player_1')
min_values = get_min_value(grouped_data)
sorted_data = sort_by_values(min_values, 'Rank_1')
top_10_ranked_players = get_first_n_rows(sorted_data, 10)

print(top_10_ranked_players)

'''

[USER (data scientist)]: Please convert these to python list. Please generate a list of the top 10 ranked players and their rankings from the ATP tennis dataset.

[YOU (AI assistant)]: here's the code to convert format :
'''
import pandas as pd
import pickle
from decision_company import read_csv_file, to_list, reset_index

# Load the dataset
atp_tennis = read_csv_file("atp_tennis.csv")

# Convert the top 10 ranked players and their rankings to a Python list
top_10_ranked_players_list = to_list(reset_index(top_10_ranked_players, drop=False))

print(top_10_ranked_players_list)

'''

[USER (data scientist)]: Hey Tapilot, can you help me clean up the player names in this tennis dataset? There are some extra spaces that need to be removed. Please generate and display a list of names extracted from the top 10 ranked players in the ATP tennis dataset.

[YOU (AI assistant)]: Of course!  :
'''
import pandas as pd
import numpy as np
import pickle
from decision_company import read_csv_file

atp_tennis = read_csv_file('atp_tennis.csv')

# Remove any extra spaces from the player names
top_10_player_names = [player[0].strip() for player in top_10_ranked_players_list]

print(top_10_player_names)

'''

[USER (data scientist)]: Awesome, thanks! Now, I want to see only the grass court matches with top 10 players from the last five years which refers to the last five years in this dataset. Can you help me filter the data? Please generate and display a DataFrame containing recent matches played on grass surfaces involving any of the top 10 ranked players in the ATP tennis dataset.

[YOU (AI assistant)]: Absolutely! Let's filter the dataset for grass court matches, top 10 players, and matches within the last five years. Here's the code you need :
'''
import pandas as pd
import numpy as np
import pickle
from decision_company import read_csv_file, check_elements_in_list, assert_series, logical_and, logical_or

atp_tennis = read_csv_file('atp_tennis.csv')

# Filter the dataset to only include grass court matches played by the top 10 players in the last five years
player_1_in_top_10 = check_elements_in_list(recent_matches['Player_1'], top_10_player_names)
player_2_in_top_10 = check_elements_in_list(recent_matches['Player_2'], top_10_player_names)
matches_with_top_10_players = logical_or(player_1_in_top_10, player_2_in_top_10)

matches_on_grass = assert_series(recent_matches['Surface'], 'Grass', 'equality')

grass_matches = recent_matches[logical_and(matches_on_grass, matches_with_top_10_players)]

print(grass_matches)

'''

[USER (data scientist)]: Cool! Now, I'd like to know how many matches each player played. Can you help me with that? Please generate and display a Series showing the number of matches played on grass surfaces by each of the top 10 ranked players in the ATP tennis dataset.

[YOU (AI assistant)]: Sure thing! We can count the occurrences of each player in the 'Player_1' and 'Player_2' columns and add them up. Here's how :
'''
import pandas as pd
import numpy as np
import pickle
from decision_company import read_csv_file, count_unique_values, fill_missing_values

atp_tennis = read_csv_file('atp_tennis.csv')

# Calculate the number of matches played by each player
matches_played = count_unique_values(grass_matches['Player_1']) + count_unique_values(grass_matches['Player_2'])
matches_played = fill_missing_values(matches_played[top_10_player_names],0)

print(matches_played)

'''

[USER (data scientist)]: Nice! Now, let's find out how many matches each player won. Please generate and display a Series showing the number of matches won on grass surfaces by each of the top 10 ranked players in the ATP tennis dataset.

[YOU (AI assistant)]: You got it! We can count the occurrences of each player in the 'Winner' column like this :
'''
import pandas as pd
import numpy as np
import pickle
from decision_company import read_csv_file, count_unique_values, fill_missing_values

atp_tennis = read_csv_file('atp_tennis.csv')

# Calculate the number of matches won by each player
matches_won = count_unique_values(grass_matches['Winner'])
matches_won = fill_missing_values(matches_won[top_10_player_names],0)

print(matches_won)

'''

[USER (data scientist)]: Great! Now, I want to know the win rate percentage for each player. Can you help me calculate that? Please generate and display a Series representing the win rate percentage on grass surfaces for each of the top 10 ranked players in the ATP tennis dataset.

[YOU (AI assistant)]: Absolutely! We can divide the number of matches won by the number of matches played and multiply by 100. Here's the code :
'''
import pandas as pd
import numpy as np
import pickle
from decision_company import read_csv_file

atp_tennis = read_csv_file('atp_tennis.csv')

# Calculate the win rate percentage for each player
win_rate_percentage = (matches_won / matches_played) * 100

print(win_rate_percentage)

'''

[USER (data scientist)]: Can you show me how to get only the grass court matches between top 10 players in the last five years? Please generate and display a DataFrame containing head-to-head matches on grass surfaces between players in the top 10 rankings in the ATP tennis dataset.

[YOU (AI assistant)]: Sure! Here's the code to filter the dataset :
'''
import pandas as pd
import numpy as np
import pickle
from decision_company import read_csv_file, check_elements_in_list

atp_tennis = read_csv_file('atp_tennis.csv')

head_to_head_matches = grass_matches[(check_elements_in_list(grass_matches['Player_1'], top_10_player_names)) & (check_elements_in_list(grass_matches['Player_2'], top_10_player_names))]

print(head_to_head_matches)

'''

[USER (data scientist)]: How do I create an empty table to store the head-to-head win-loss records? Please generate and display a DataFrame representing a head-to-head matrix initialized with zeros for the top 10 ranked players in the ATP tennis dataset.

[YOU (AI assistant)]: No problem! Here's a simple way to create an empty table for the head-to-head records :
'''
import pandas as pd
import numpy as np
import pickle
from decision_company import read_csv_file, create_zeros_array, create_dataframe

atp_tennis = read_csv_file('atp_tennis.csv')

# Assuming grass_matches and top_10_player_names are already defined
head_to_head_array = create_zeros_array((10, 10))
head_to_head_matrix = create_dataframe(head_to_head_array, columns=top_10_player_names, index=top_10_player_names)

print(head_to_head_matrix)

'''

[USER (data scientist)]: How can I fill the table with the head-to-head win-loss records? Please generate a DataFrame to update and display a head-to-head matrix, indicating wins among the top 10 ranked players on grass surfaces in the ATP tennis dataset.

[YOU (AI assistant)]: Let me show you how to fill the table with the head-to-head records :
'''
import pandas as pd
import numpy as np
import pickle
from decision_company import read_csv_file, iterate_rows, access_dataframe_loc, update_dataframe_loc

atp_tennis = read_csv_file('atp_tennis.csv')

for index, row in iterate_rows(head_to_head_matches):
    winner = row['Winner']
    loser = row['Player_1'] if row['Player_1'] != winner else row['Player_2']
    current_value = access_dataframe_loc(head_to_head_matrix, winner, loser)
    update_dataframe_loc(head_to_head_matrix, winner, loser, current_value + 1)

print(head_to_head_matrix)

'''

[USER (data scientist)]: Hey, I've got this dataset of tennis matches on grass court and I want to find out how well top 10 players perform in specific rounds of grass court tournaments. Can you give me a hand? Please generate and display a list of specific tennis match rounds.

[YOU (AI assistant)]: Of course, happy to help! Let's start by listing the rounds in the tournament. Here's a simple way to do it :
'''
import pandas as pd
import numpy as np
import pickle
from decision_company import read_csv_file

atp_tennis = read_csv_file('atp_tennis.csv')

rounds = ['Early Round', 'Quarterfinals', 'Semifinals', 'Final']

print(rounds)

'''

[USER (data scientist)]: Nice, now I'd like to set up an empty list where I can store each player's performance data for every round. Please initialize and display an empty list for storing tennis performance data.

[YOU (AI assistant)]: No problem, here's how you can create an empty list :
'''
import pandas as pd
import numpy as np
import pickle
from decision_company import read_csv_file

atp_tennis = read_csv_file('atp_tennis.csv')

performance_data_list = []

print(performance_data_list)

'''

[USER (data scientist)]: Cool, now let's go through the top 10 players and check their stats in early round, how many matches they played, how many they won, and their winning percentage. BTW, the early round refers to 1st-4th round. Please calculate and display a value of the win rate for each top 10 ranked player in specific rounds of grass surface matches in the ATP tennis dataset.

[YOU (AI assistant)]: Sure thing! You can use nested loops to go through each player and round, then filter your dataset to grab the matches played by that player in that round. Here's the code you'll need :
'''
import pandas as pd
import numpy as np
import pickle
from decision_company import read_csv_file, assert_series, logical_or, logical_and

atp_tennis = read_csv_file('atp_tennis.csv')

# Calculate the performance data for each player in each round
for player in top_10_player_names:
    for round_name in rounds:
        if round_name == 'Early Round':
            # Filter the dataset to only include matches played by the player in the early rounds
            player_round_matches = grass_matches[logical_or(logical_or(logical_or(assert_series(grass_matches['Round'], '1st Round', 'equality'), assert_series(grass_matches['Round'], '2nd Round', 'equality')), assert_series(grass_matches['Round'], '3rd Round', 'equality')), assert_series(grass_matches['Round'], '4th Round', 'equality')) & logical_or(assert_series(grass_matches['Round'], player, 'equality'), assert_series(grass_matches['Round'], player, 'equality'))]
        else:
            # Filter the dataset to only include matches played by the player in the specific round
            player_round_matches = grass_matches[logical_and(assert_series(grass_matches['Round'], round_name, 'equality'), logical_or(assert_series(grass_matches['Round'], player, 'equality'), assert_series(grass_matches['Round'], player, 'equality')))]

        # Calculate the number of matches played
        matches_played = len(player_round_matches)

        # Calculate the number of matches won
        matches_won = len(player_round_matches[assert_series(player_round_matches['Winner'], player, 'equality')])

        # Calculate the win rate
        win_rate = (matches_won / matches_played) * 100 if matches_played > 0 else 0

print(win_rate)

'''

[USER (data scientist)]: That's perfect! Now I'd like to add each player's performance data for each round to the list we made earlier. Please generate and display a list containing performance data, including matches played, won, and win rate for each top 10 ranked player in specific rounds of grass surface matches in the ATP tennis dataset.

[YOU (AI assistant)]: You got it! You can add the performance data to your list with a dictionary like this :
'''
import pandas as pd
import numpy as np
import pickle
from decision_company import read_csv_file, assert_series, logical_or, logical_and

atp_tennis = read_csv_file('atp_tennis.csv')

# Calculate the performance data for each player in each round
for player in top_10_player_names:
    for round_name in rounds:
        if round_name == 'Early Round':
            # Filter the dataset to only include matches played by the player in the early rounds
            player_round_matches = grass_matches[logical_or(logical_or(logical_or(assert_series(grass_matches['Round'], '1st Round', 'equality'), assert_series(grass_matches['Round'], '2nd Round', 'equality')), assert_series(grass_matches['Round'], '3rd Round', 'equality')), assert_series(grass_matches['Round'], '4th Round', 'equality')) & logical_or(assert_series(grass_matches['Round'], player, 'equality'), assert_series(grass_matches['Round'], player, 'equality'))]
        else:
            # Filter the dataset to only include matches played by the player in the specific round
            player_round_matches = grass_matches[logical_and(assert_series(grass_matches['Round'], round_name, 'equality'), logical_or(assert_series(grass_matches['Player_1'], player, 'equality'), assert_series(grass_matches['Player_2'], player, 'equality')))]

        # Calculate the number of matches played
        matches_played = len(player_round_matches)

        # Calculate the number of matches won
        matches_won = len(player_round_matches[assert_series(player_round_matches['Winner'], player, 'equality')])

        # Calculate the win rate
        win_rate = (matches_won / matches_played) * 100 if matches_played > 0 else 0

        # Append the performance data to the list
        performance_data_list.append({'Player': player, 'Round': round_name, 'Matches Played': matches_played, 'Matches Won': matches_won, 'Win Rate': win_rate})

print(performance_data_list)

'''

[USER (data scientist)]: Lastly, I want to turn the list with all the performance data into a pandas DataFrame. Please compile and display a list of detailed performance data, including the number of matches played, won, and the win rate for each top 10 ranked player in specific rounds on grass surfaces in the ATP tennis dataset.

[YOU (AI assistant)]: Easy peasy! Just use this code to transform your list into a DataFrame :
'''
import pandas as pd
import numpy as np
import pickle
from decision_company import read_csv_file, create_dataframe

atp_tennis = read_csv_file('atp_tennis.csv')

# Convert the list to a DataFrame
performance_data = create_dataframe(performance_data_list)

print(performance_data)

'''

[USER (data scientist)]: I have a dataframe of tennis matches played on grass courts. I want to find notable opponents that the top 10 players struggle against. Can you help me write a code to do that? Please identify and display a list of opponents who have won at least three matches against the top 10 ranked players on grass surfaces in the ATP tennis dataset. Specifically, you can generate and display a list of opponents who have won at least three matches against the top 10 ranked players on grass surfaces in the ATP tennis dataset.

My template of code snippet is:

---BEGIN CODE TEMPLATE---

import pandas as pd
import numpy as np
import pickle
from decision_company import read_csv_file,

# please import the necessary private functions from decision_company first

atp_tennis = read_csv_file('atp_tennis.csv')

# YOUR SOLUTION BEGIN:
<code1>
[COMPLETE YOUR CODE] 
</code1>
# YOUR SOLUTION END

print(notable_opponents_list)

# save data
pickle.dump(notable_opponents_list,open("./pred_result/notable_opponents_list.pkl","wb"))

---END CODE TEMPLATE---

Please note that you have to generate the WHOLE python code instead of code segments based on the code snippet using Pandas library 2.0.3 version and Matplotlib library 3.7.4 version. You must keep all comments in code snippet unchanged.

[YOU (AI assistant)]: Sure, I can help you with that. First, Here's a code snippet to find the notable opponents who have won against the top 10 players:
'''
import pandas as pd
import numpy as np
import pickle
from decision_company import read_csv_file,

# please import the necessary private functions from decision_company first

atp_tennis = read_csv_file('atp_tennis.csv')

# YOUR SOLUTION BEGIN:
